package net.huashitong.ssydt.provider.exam.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.huashitong.ssydt.exam.entity.vo.ExamPaperQuestionInVO;
import net.huashitong.ssydt.exam.entity.vo.PaperQuestionOutVO;
import net.huashitong.ssydt.provider.exam.service.SsExamPaperQuestionService;
import net.huashitong.ssydt.provider.web.model.Result;
import net.huashitong.ssydt.provider.web.utils.ResultUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.ArrayList;

/**
 * 试卷管理（后台）
 *
 * @author hemj
 * @version 2017/9/11
 */
@Api(value = "/exam/paper", tags = {"试卷题目管理（后台）"})
@RestController
@RequestMapping("/exam/paper")
public class SsExamPaperQuestionController {

	private SsExamPaperQuestionService ssExamPaperQuestionService;

	@Autowired
	public SsExamPaperQuestionController(SsExamPaperQuestionService ssExamPaperQuestionService) {
		this.ssExamPaperQuestionService = ssExamPaperQuestionService;
	}

	@ApiOperation(value = "加载试卷题目与选项", notes = "加载试卷题目与选项")
	@GetMapping("/{paperId}/questions")
	public Result<ArrayList<PaperQuestionOutVO>> listPaperQuestionsAndOptions(@PathVariable Long paperId) {
		return ResultUtils.getSuccessResults((ArrayList<PaperQuestionOutVO>) ssExamPaperQuestionService.listPaperQuestionsAndOptions(paperId));
	}

	@ApiOperation(value = "往试卷中追加题目", notes = "往试卷中追加题目")
	@PostMapping("/{paperId}/questions")
	public Result<String> appendPaperQuestion(@PathVariable Long paperId,
											  @Valid @RequestBody ExamPaperQuestionInVO examPaperQuestionInVO) {
		ssExamPaperQuestionService.appendPaperQuestion(paperId, examPaperQuestionInVO);
		return ResultUtils.getSuccessResults();
	}

	@ApiOperation(value = "试卷题目顺序修改", notes = "试卷题目顺序修改（所有试卷题目列表）")
	@PutMapping("/{paperId}/questions")
	public Result<String> updatePaperQuestion(@PathVariable Long paperId,
											  @Valid @RequestBody ExamPaperQuestionInVO examPaperQuestionInVO) {
		ssExamPaperQuestionService.updatePaperQuestion(paperId, examPaperQuestionInVO);
		return ResultUtils.getSuccessResults();
	}

	@ApiOperation(value = "删除试卷题目", notes = "删除试卷题目")
	@DeleteMapping("/{paperId}/questions")
	public Result<String> deletePaperQuestion(@PathVariable Long paperId,
											  @Valid @RequestBody ExamPaperQuestionInVO examPaperQuestionInVO) {
		ssExamPaperQuestionService.deletePaperQuestion(paperId, examPaperQuestionInVO);
		return ResultUtils.getSuccessResults();
	}
}
